import Vue from 'vue'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets
import Element from 'element-ui'
import './styles/element-variables.scss'

import '@/styles/index.scss' // global css

import store from './store'
import Print from 'vue-print-nb'
import i18n from './lang' // internationalization
import './icons' // icon
import './utils/error-log' // error log
import request from '@/utils/request'

import * as filters from './filters' // global filters
import { hasPermission, hasNoPermission, hasAnyPermission } from './utils/permissionDirect'
import uploader from 'vue-simple-uploader'

import router from './router'
import App from './App'

const Plugins = [
  hasPermission,
  hasNoPermission,
  hasAnyPermission
]

Plugins.map((plugin) => {
  Vue.use(plugin)
})

Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(uploader)
Vue.use(Print)

Vue.prototype.$post = request.post
Vue.prototype.$get = request.get
Vue.prototype.$put = request.put
Vue.prototype.$delete = request.delete
Vue.prototype.$download = request.download
Vue.prototype.$upload = request.upload
Vue.prototype.$login = request.login
Vue.prototype.$rowData = [
  "A",
  "B",
  "C",
  "D",
  "E",
  "F",
  "G",
  "H",
  "I",
  "J",
  "K",
  "L",
  "M",
  "N",
  "O",
  "P",
  "Q",
  "R",
  "S",
  "T",
  "U",
  "V",
  "W",
  "X",
  "Y",
  "Z"
]

// 条形码号验证
Vue.prototype.$barCodeNum = (rule, value, callback) => {
  if (value < 14000000000) {
    callback(new Error());
    return true
  }
  if (value > 20999999999) {
    callback(new Error());
    return true
  }
  callback();
}
// 孕周验证
Vue.prototype.$weeksNum = (rule, value, callback) => {
  if (value < 20) {
    callback(new Error());
    return true
  }
  if (value > 50) {
    callback(new Error());
    return true
  }
  callback();
}
// 孕天验证
Vue.prototype.$daysNum = (rule, value, callback) => {
  if (value < 1) {
    callback(new Error());
    return true
  }
  if (value > 6) {
    callback(new Error());
    return true
  }
  callback();
}
// 体重验证
Vue.prototype.$weightNum = (rule, value, callback) => {
  if (value < 600) {
    callback(new Error());
    return true
  }
  if (value > 8000) {
    callback(new Error());
    return true
  }
  callback();
}
// 免费券验证
Vue.prototype.$freeNum = (rule, value, callback) => {
  if (value) {
    if (value < 200110001) {
      callback(new Error());
      return true
    }
    if (value > 200145000) {
      callback(new Error());
      return true
    }
  }
  callback();
}
// 排序 true 大到小---  false 小到大
Vue.prototype.$keysrt = (array, key) => {
  return array.sort(function (a, b) {
    var x = a[key];
    var y = b[key];
    return ((x < y) ? -1 : ((x < y) ? 1 : 0));
  });
}


// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
